package com.woniu.user.controller;

import com.woniu.common.entity.ResponseResult;
import com.woniu.user.entity.Advice;
import com.woniu.user.service.AdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author author
 * @create 2021/5/19
 */
@RequestMapping("/advice")
@RestController
public class AdviceController {

    @Autowired
    AdviceService adviceService;

    @GetMapping("all")
    public ResponseResult<List<Advice>> selectAllAdvice() {
        return new ResponseResult<>(200, null, "ok", adviceService.selectAllAdvice(), null);
    }

    @PostMapping("/add")
    public ResponseResult<String> addAdvice(@RequestBody Advice advice) {

        if (adviceService.addAdvice(advice)) {
            return new ResponseResult<>(200, null, "建议成功", null, null);
        }

        return new ResponseResult<>(500, null, "建议失败，请稍后重试", null, null);
    }

    @GetMapping("/updateStatus")
    public ResponseResult<String> updateStatusById(Integer id) {

        if (adviceService.updateStatusById(id)) {
            return new ResponseResult<>(200, null, "审核成功", null, null);
        }

        return new ResponseResult<>(500, null, "审核失败，请稍后重试", null, null);
    }

    @GetMapping("/addReply")
    public ResponseResult<String> addReply(String reply) {

        if (adviceService.addReply(reply)) {
            return new ResponseResult<>(200, null, "回复成功", null, null);
        }

        return new ResponseResult<>(500, null, "回复失败，请稍后重试", null, null);
    }

}
